package message.receive;

import io.netty.buffer.ByteBuf;
import message.Receive;
import message.ReceiveType;
import util.Constants;

public class LoginReceive implements Receive
{
    private byte   code;
    private String codeMsg;

    public byte getCode()
    {
        return code;
    }

    public void setCode(byte code)
    {
        this.code = code;
    }

    public String getCodeMsg()
    {
        return codeMsg;
    }

    public void setCodeMsg(String codeMsg)
    {
        this.codeMsg = codeMsg;
    }

    @Override
    public ReceiveType type()
    {
        return ReceiveType.LOGIN;
    }

    @Override
    public void readFromBuf(ByteBuf buf)
    {
        code = buf.readByte();
        int length = buf.readInt();
        byte[] bytes = new byte[length];
        buf.readBytes(bytes);
        codeMsg = new String(bytes,Constants.CHARSET);
    }
}
